/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-10-17 11:15:37
 * @LastEditTime: 2022-10-24 18:53:46
 */
import {
  ADD_TEMPLATETASK_LIST,
  GET_TEMPLATETASK_LIST,
  DELETE_TEMPLATETASK_ITEM,
  EDIT_TEMPLATETASK,
  SET_ARCHIVETYPE,
  CLEAR_TEMPLATE
} from '../constants';
import { delItemByIdArray, insertItem, editItemById } from '@/utils/list';
export const ArchivesDetectionReducer = (state, action) => {
  switch (action.type) {
    /* 设置检测模板 */
    case ADD_TEMPLATETASK_LIST: {
      return {
        ...state,
        DetectionTemplate: insertItem(action.data, state.DetectionTemplate),
        DetectionTemplateId: action.data.id
      };
    }
    /* 获取模板列表 */
    case GET_TEMPLATETASK_LIST: {
      return { ...state, DetectionTemplate: action.data };
    }
    /**
     * @description: 删除检测模板列表项目
     */
    case DELETE_TEMPLATETASK_ITEM: {
      return {
        ...state,
        DetectionTemplate: delItemByIdArray(action.ids, state.DetectionTemplate)
      };
    }
    // 修改检测模板
    case EDIT_TEMPLATETASK:
      return {
        ...state,
        DetectionTemplate: editItemById(action.id, action.data, state.DetectionTemplate)
      };
    /* 设置外出选中 */
    case SET_ARCHIVETYPE: {
      return { ...state, archiveTypeList: action.data };
    }
    /* 清空选中模板 */
    case CLEAR_TEMPLATE: {
      return { ...state, DetectionTemplate: [] };
    }
    default:
      console.log('untouched', action);
      return state;
  }
};
